﻿using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using RGBFinder.Resources;
using System.Threading;


namespace RGBFinder
{
    public class MainViewModel : INotifyPropertyChanged
    {


        public MainViewModel()
        {

            this.Ads = new ObservableCollection<AdsViewModel>();
            this.Scores = new ObservableCollection<ScoresViewModel>();
            this.GameTypes = new ObservableCollection<GameTypeViewModel>();
        }

        /// <summary>
        /// A collection for ItemViewModel objects.
        /// </summary>



        public ObservableCollection<AdsViewModel> Ads { get; private set; }
        public ObservableCollection<ScoresViewModel> Scores { get; private set; }
        public ObservableCollection<GameTypeViewModel> GameTypes { get; private set; }

        private string _sampleProperty = "Sample Runtime Property Value";
        /// <summary>
        /// Sample ViewModel property; this property is used in the view to display its value using a Binding
        /// </summary>
        /// <returns></returns>
        public string SampleProperty
        {
            get
            {
                return _sampleProperty;
            }
            set
            {
                if (value != _sampleProperty)
                {
                    _sampleProperty = value;
                    NotifyPropertyChanged("SampleProperty");
                }
            }
        }

        public bool IsDataLoaded
        {
            get;
            private set;
        }

        /// <summary>
        /// Creates and adds a few ItemViewModel objects into the Items collection.
        /// </summary>
        public void LoadData()
        {
            foreach (var app in StateAndOptions.state.applications2)
            {
                Ads.Add(new AdsViewModel() { Name = app.name, Description = app.description, ID = app.id, ImageUri = new Uri(app.imageUri, UriKind.Absolute) });
            }



            Scores.Add(new ScoresViewModel() { Score = Strings.Score, Name = Strings.Name, Index = Strings.Rank });

            GameTypes.Add(new GameTypeViewModel() { Name = Strings.Easy, Description = Strings.Easy_Desc });
            GameTypes.Add(new GameTypeViewModel());
            GameTypes.Add(new GameTypeViewModel() { Name = Strings.Normal, Description = Strings.Normal_Desc });
            GameTypes.Add(new GameTypeViewModel());
            GameTypes.Add(new GameTypeViewModel() { Name = Strings.Hard, Description = Strings.Hard_Desc });

            this.IsDataLoaded = true;
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}